#!/usr/bin/env bash
jar_processor="zy_smarthome_socket.jar"
IP_ADDR=`/usr/sbin/ifconfig |grep inet |awk '{print $2}'|head -1`
#进程检测
process() {
  for jar in  $jar_processor
    do
    JAR_PROCESS=`ps -ef |grep $jar |grep -v grep |wc -l`
    if [ ! -n "jar_processor" ]
    then
        break
    else
        if [ $JAR_PROCESS = 0 ]
        then
               echo "$IP_ADDR:$jar 进程已停止，请确认是否正常,正在重启进程"
               #检查端口号是否被占用
               JAVA_PORT = netstat -anp|grep 33168
               if [ $JAVA_PORT != 0 ]
               then
                kill -9 $(lsof -i:33168|awk '{print $2}')
                fi
               echo "清空端口号，准备重启"
               nohup java -jar -Xms5029m -Xmx5029m -XX:NewSize=100m -XX:MaxNewSize=100m -XX:MaxDirectMemorySize=5029m  -XX:+UseG1GC -XX:+PrintGC -XX:+PrintGCDateStamps -Xloggc:/home/admin/springboot/webapps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=50m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/admin/springboot/webapps /home/admin/springboot/webapps/zy_smarthome_socket.jar > zy_smarthome_socket.log 2>&1 &
               echo "正在重启中"
        fi
    fi
   done
}
process